#include <iostream>
using namespace std;

struct TreeNode
{
    TreeNode* left;
    TreeNode* right;
    int val;
    TreeNode(int x) 
        : val(x)
        , left(nullptr)
        , right(nullptr) {}
};
int maxDepth(TreeNode* root)
{
    // write code here
    int left = 0;
    int right = 0;
    if (root == nullptr)
    {
        return 0;
    }
    left = maxDepth(root->left);
    right = maxDepth(root->right);

    return left > right ? left + 1 : right + 1;
}